<?php
namespace app\common\controller;

use think\Controller;
use think\Db;

class SuperadminBase extends Controller
{
    
    public function _initialize(){
    	
    	parent::_initialize();
       
    	if (empty(session('adminid'))) 
    	{
    		return $this->redirect('login/index');
    	}

    	$admininfo = Db::table('yup_admin')->where('id',session('adminid'))->find();

    	if (!$admininfo || $admininfo['is_disable'] == 1) {
    		 
    		 return $this->redirect('login/index');
    	}


       
        $qxarr = Db::name('quanxian')->field('directory_id')->where('role_id',$admininfo['role_id'])->column('directory_id');

        $acarr = Db::name('directory')->where('id','in',$qxarr)->field('action')->column('action');

        //halt($acarr);
        //无需验证的方法
        $notCheck   = ['Login/index','Login/yanzheng','Login/bey','Login/doedit','Index/index','Index/statis','Uploadfile/getfile'];


        $controller =$this->request->controller();
        $action     =$this->request->action();
        $urlName    =$controller.'/'.$action;


        if (!in_array($urlName, $notCheck) && $admininfo['type'] == 2) {
               
            if (!in_array($urlName, $acarr)) {

                die("<script>alert('您没有该目录权限')</script>");
            }   

        }
        
        $arr = [];
        $arr['add'] = true;
        $arr['edit'] = true;
        $arr['del'] = true;
        $arr['look'] = true;
        $arr['shenhe'] = true;
        $arr['list'] = true;
        

        if ($action == 'index') {

            if ($admininfo['type'] == 2) {

                $arr['add'] = in_array($controller."/add", $acarr);
                $arr['edit'] = in_array($controller."/edit", $acarr);
                $arr['del'] = in_array($controller."/del", $acarr);
                $arr['look'] = in_array($controller."/look", $acarr);
                $arr['shenhe'] = in_array($controller."/shenhe", $acarr);
                $arr['list'] = in_array('Abnormal/glist', $acarr);
              
            }
            

        }

        //halt($arr);
        $this->assign('qxarr',$arr);
        $this->assign('acarr',$acarr);

       
        

    }
}
